package com.tang.concurrentlearn.base.abc.join;

import com.tang.concurrentlearn.tools.SleepTools;

/**
 * 使用Join让线程有序
 *
 * @author tang
 * @since 2024/5/19 17:32
 */
public class JoinSort {

    public static void main(String[] args) {

        Thread t1 = new Thread("T1") {
            @Override
            public void run() {
                System.out.println("T1执行咯");
            }
        };

        Thread t2 = new Thread("T2") {
            @Override
            public void run() {
                try {
                    t1.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("T2执行咯");
            }
        };

        Thread t3 = new Thread("T3") {
            @Override
            public void run() {
                try {
                    t2.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("T3执行咯");
            }
        };

        t3.start();
        t2.start();
        t1.start();
        
    }

    private static synchronized void synClass() {
        System.out.println(Thread.currentThread().getName() + "synClass going ...");
        SleepTools.second(1);
    }
    
}
